package com.egg.ylt.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.Utils.StringUtil;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;
import com.yonyou.framework.library.common.utils.ToastUtil;
import com.yonyou.framework.library.manager.ActivityTaskManager;

import butterknife.BindView;
import butterknife.OnClick;

public class ACT_UserLogin extends BaseActivity {


    @BindView(R.id.root_layout)
    LinearLayout mRootLayout;
    @BindView(R.id.iv_delete_login)
    ImageView ivDeleteLogin;
    @BindView(R.id.edit_phone_login)
    EditText editPhoneLogin;
    @BindView(R.id.btn_next_login)
    TextView btnNextLogin;
    @BindView(R.id.tv_pwd_login)
    TextView tvPwdLogin;
    @BindView(R.id.login_iv_wx)
    ImageView loginIvWx;
    @BindView(R.id.login_iv_qq)
    ImageView loginIvQq;
    @BindView(R.id.tv_user_protocol)
    TextView tvUserProtocol;

    private AppSharedPreferences mSp;
    // 定义一个变量，来标识是否退出
    private static boolean isExit = false;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            isExit = false;
        }
    };

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_uset_login;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, mRootLayout);
        mSp = new AppSharedPreferences(mContext);
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return true;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return TransitionMode.BOTTOM;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }


    @OnClick({R.id.iv_delete_login, R.id.btn_next_login, R.id.tv_pwd_login, R.id.tv_user_protocol})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_delete_login://退出登录
                finish();
                break;
            case R.id.btn_next_login://下一步
                Bundle mBundle = new Bundle();
                String phone = editPhoneLogin.getText().toString();
                mBundle.putString("phone", phone);
                mBundle.putInt("type", Constants.PHONE_LOGIN_TO_CODE);
                if (!StringUtil.isPhone(phone)) {
                    ToastUtil.makeText(mContext, "手机号不正确", false);
                    return;
                }
                readyGo(ACT_ImportCode.class, mBundle);
                break;
            case R.id.tv_pwd_login://账号密码登录
                readyGo(ACT_AccountPasswordLogin.class);
                break;
            case R.id.tv_user_protocol://用户协议
                readyGo(ACT_UserProtocol.class);
                break;
        }
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            exit();
//            return false;
//        }
//        return super.onKeyDown(keyCode, event);
//    }
//
//    private void exit() {
//        if (!isExit) {
//            isExit = true;
//            ToastUtil.makeText(mContext, "再按一次退出程序", false);
//            // 利用handler延迟发送更改状态信息
//            mHandler.sendEmptyMessageDelayed(0, 2000);
//        } else {
//            finish();
////            System.exit(0);
//            ActivityTaskManager.getInstance().closeAllActivity();
//        }
//    }
}
